package com.fhzn.boss.service.impl;

import com.fhzn.boss.entity.Resource;
import com.fhzn.boss.mapper.ResourceMapper;
import com.fhzn.boss.mapper.UserMapper;
import com.fhzn.boss.service.AuthService;
import com.fhzn.boss.web.converter.ResourceConverter;
import com.fhzn.boss.web.converter.UserConverter;
import com.fhzn.boss.web.request.AuthQueryRequest;
import com.fhzn.boss.web.vo.AuthQueryResponseVO;
import com.fhzn.boss.web.vo.ResourceVO;
import com.fhzn.boss.web.vo.UserVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 老顾
 * @apiNote
 * @since 2024/1/2
 */
@Service
@RequiredArgsConstructor
public class AuthServiceImpl implements AuthService {

    private final UserMapper userMapper;
    private final ResourceMapper resourceMapper;


    @Override
    public AuthQueryResponseVO query(AuthQueryRequest request) {
        request.checkBaseParams();
        AuthQueryResponseVO data = new AuthQueryResponseVO();
        UserVO user = UserConverter.fromUser(userMapper.findUserByNickName(request.getHandler()));
        data.setUser(user);
        List<Resource> resources = resourceMapper.findResourcesByAppCode(request.getInvokeAppName());
        data.setResourceList(ResourceConverter.convertToVoList(resources));
        List<ResourceVO> resourceList = data.getResourceList();
        data.setResourceList(resourceList);
        return data;
    }

}
